import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

/**
 * Generated with window builder with a few edits <br />
 * Screen for formating from bibTex part.
 * @author cerko, mydlo
 *
 */
public class BasicView extends JFrame {
	
	private static int windowWidth = 800;
	private static int windowHeight = 630;
	private static String backgroundPath = "img/basicExport/basicViewBackground.jpg";

	private JPanel contentPane;
	private JPanel backgroundPanel;
	private static Frontend frontend;
	public static JFrame bibView;
	public static JFrame reformatView;
	
	private JFrame frame;

	/**
	 * Create the frame.
	 */
	public BasicView(Frontend frontend, JFrame sender) {
		BasicView.frontend = frontend;
		BasicView.frontend.setBasicView(this);
		frame = this;
		
		bibView = new SaveIntoBibView(this);
		reformatView = new ReformatTexView(this);
		sender.setVisible(false);
		setResizable(false);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setSize(windowWidth, windowHeight);
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		
	//	button = new JButton(new ImageIcon(buttonIcon));
		
		JButton btnRefsfrombib = new JButton(new ImageIcon("img/basicExport/addReferenceButton.png"));
		btnRefsfrombib.setBorder(BorderFactory.createEmptyBorder());
		btnRefsfrombib.setOpaque(false);
		btnRefsfrombib.setContentAreaFilled(false);
		
		btnRefsfrombib.addMouseListener(new ButtonMouseListener(new ImageIcon("img/buttons/addReferenceButtonA.png"), new ImageIcon("img/buttons/addReferenceButton.png"), btnRefsfrombib));

		//JButton btnRefsfrombib = new JButton("refsFromBib");
		btnRefsfrombib.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
				BasicView.frontend.setFirstModeView();
			}
		});
		btnRefsfrombib.setBounds(100, 130, 203, 203);
		contentPane.add(btnRefsfrombib);
		
		JButton  btnTexReformatdTo = new JButton(new ImageIcon("img/basicExport/reformateButton.png"));
		btnTexReformatdTo.setBorder(BorderFactory.createEmptyBorder());
		btnTexReformatdTo.setOpaque(false);
		btnTexReformatdTo.setContentAreaFilled(false);
		
		btnTexReformatdTo.addMouseListener(new ButtonMouseListener(new ImageIcon("img/buttons/reformateButtonA.png"), new ImageIcon("img/buttons/reformateButton.png"), btnTexReformatdTo));
		
		btnTexReformatdTo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				BasicView.reformatView.setVisible(true);
			}
		});
		btnTexReformatdTo.setBounds(269, 310, 203, 203);
		contentPane.add(btnTexReformatdTo);
		
		JButton  btnSaveIntoBibtex = new JButton(new ImageIcon("img/basicExport/createBibtexButton.png"));
		btnSaveIntoBibtex.setBorder(BorderFactory.createEmptyBorder());
		btnSaveIntoBibtex.setOpaque(false);
		btnSaveIntoBibtex.setContentAreaFilled(false);
		
		btnSaveIntoBibtex.addMouseListener(new ButtonMouseListener(new ImageIcon("img/buttons/createBibtexButtonA.png"), new ImageIcon("img/buttons/createBibtexButton.png"), btnSaveIntoBibtex));
		
		btnSaveIntoBibtex.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
				BasicView.bibView.setVisible(true);
			}
		});
		btnSaveIntoBibtex.setBounds(500, 240, 203, 203);
		contentPane.add(btnSaveIntoBibtex);
		GraphicsConfiguration gc = getGraphicsConfiguration();
		Rectangle bounds = gc.getBounds();
		setLocation(
				(int) ((bounds.width / 2) - (windowWidth / 2)),
				(int) ((bounds.height / 2) - (windowHeight / 2))
				);
		
		backgroundPanel = new JPanel(){
			@Override
			 public void paintComponent(Graphics g){
				Image img = null;
				try {
					img = ImageIO.read(new File(backgroundPath));
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
                g.drawImage(img, 0, 0, null);
            } 
		};
		
		backgroundPanel.setBounds(0, 0, 800, 800);
		contentPane.add(backgroundPanel);
		
		setVisible(true);
	}
}
